package com.zhan.picturebackend.api.imagesearch;

import com.zhan.picturebackend.api.imagesearch.model.SoImageSearchResult;
import com.zhan.picturebackend.api.imagesearch.sub.GetSoImageListApi;
import com.zhan.picturebackend.api.imagesearch.sub.GetSoImageUrlApi;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 360搜图图片搜索接口
 * 这里用了 门面模式
 */
@Slf4j
public class SoImageSearchApiFacade {

    /**
     * 搜索图片
     *
     * @param imageUrl 需要以图搜图的图片地址
     * @param start    开始查询的下标，可以避免查询到的是同一张图片
     * @return 图片搜索结果列表
     */
    public static List<SoImageSearchResult> searchImage(String imageUrl, Integer start) {
        String soImageUrl = GetSoImageUrlApi.getSoImageUrl(imageUrl);
        List<SoImageSearchResult> imageList = GetSoImageListApi.getImageList(soImageUrl, start);
        return imageList;
    }

    public static void main(String[] args) {
        // 测试以图搜图功能
//        String imageUrl = "https://st.so.com/r?src=st&srcsp=home&img_url=https://picture-1359263766.cos.ap-shanghai.myqcloud.com/public/1922134344799744001/2025-05-17_p9wpoeQmHLUsINmq.webp&submittype=imgurl";
        String imageUrl = "https://picture-1359263766.cos.ap-shanghai.myqcloud.com/space/1/2025-05-21_fx6Pztyz1P9WxjLz.webp";
        List<SoImageSearchResult> resultList = searchImage(imageUrl, 0);
        System.out.println("结果列表" + resultList);
    }
}
